package com.example.bicycle.domain.entity;


import java.io.Serializable;
import java.text.DecimalFormat;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
/**
 * (Battery)表实体类
 *
 * @author makejava
 * @since 2023-08-02 21:29:49
 */
@SuppressWarnings("serial")
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("batteries")
public class Battery  {
    @TableId
    @TableField("battery_id")
    private Integer batteryId;

    @TableField("voltage_v1")
    private Float voltageV1;
    
    @TableField("voltage_v2")
    private Float voltageV2;
    
    @TableField("temperature_t1")
    private Float temperatureT1;
    
    @TableField("temperature_t2")
    private Float temperatureT2;
    
    @TableField("bike_id")
    private Integer bikeId;

    @TableField("voltage_d")
    private Float voltage_d;

    @TableField("electricity")
    private String electricity;


    public void copyAttributesFrom(Battery other){
        if(other.getElectricity() != null&&other.getElectricity()!=this.electricity) {
            this.electricity = other.getElectricity();
        }
        if(other.getVoltageV1() != null&&other.getVoltageV1()!=this.voltageV1) {
            this.voltageV1 = other.getVoltageV1();
        }
        if(other.getVoltageV2() != null&&other.getVoltageV2()!=this.voltageV2) {
            this.voltageV2 = other.getVoltageV2();
        }
        if(other.getTemperatureT1() != null&&other.getTemperatureT1()!=this.temperatureT1) {
            this.temperatureT1 = other.getTemperatureT1();
        }
        if(other.getTemperatureT2() != null&&other.getTemperatureT2()!=this.temperatureT2) {
            this.temperatureT2 = other.getTemperatureT2();
        }
        calculateVdElectricity();
    }

    public void calculateVdElectricity () {
        Float voltage_d_max = 1.5f;
        voltage_d = Math.abs(voltageV1 - voltageV2);
        Float temp = voltage_d / voltage_d_max * 100;
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        String ans = decimalFormat.format(temp);
        this.electricity = ans + "%";
    }
}

